package com.ethink.platform.controller.warehouse;

import com.ethink.framework.common.web.BaseController;
import com.ethink.framework.common.web.context.SPRequestContextHolder;
import com.ethink.framework.common.web.response.CommonResponse;
import com.ethink.platform.controller.order.info.ExportInfo;
import com.ethink.platform.manager.ExportManager;
import com.ethink.warehouse.api.MateInventoryAdjustLogFacade;
import com.ethink.warehouse.api.info.MateInventoryAdjustLogInfo;
import com.ethink.warehouse.api.info.MateInventoryAdjustLogModeInfo;
import com.ethink.warehouse.api.request.*;
import com.ethink.warehouse.api.response.MateInventoryAdjustLogGetDetailResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 库存矫正记录 Controller
 *
 * @author default
 * @date 2022-11-17
 */
@Tag(name = "MateInventoryAdjustLogController", description = "库存矫正记录 Controller")
@RestController
@Slf4j
@RequestMapping("platform-server/v1/warehouse-service")
public class MateInventoryAdjustLogController extends BaseController {

    @Autowired
    private MateInventoryAdjustLogFacade mateInventoryAdjustLogFacade;

    @Resource
    private ExportManager exportManager;

    @Operation(summary = "分页查询")
    @GetMapping("/mateInventoryAdjustLog/query")
    public CommonResponse<List<MateInventoryAdjustLogInfo>> queryMateInventoryAdjustLog(MateInventoryAdjustLogQueryRequest request) {
        return succeedWithPage(mateInventoryAdjustLogFacade.queryMateInventoryAdjustLog(request));
    }

    @Operation(summary = "导出")
    @GetMapping("/mateInventoryAdjustLog/export")
    public CommonResponse<ExportInfo> exportMateInventoryAdjustLog(MateInventoryAdjustLogQueryRequest request) {
        return succeedWith(exportManager.exportMateInventoryAdjustLog(request));
    }

    @Operation(summary = "货品模式分页查询")
    @GetMapping("/mateInventoryAdjustLog/queryMode")
    public CommonResponse<List<MateInventoryAdjustLogModeInfo>> queryMateInventoryAdjustLogMode(MateInventoryAdjustLogQueryModeRequest request) {
        return succeedWithPage(mateInventoryAdjustLogFacade.queryMateInventoryAdjustLogMode(request));
    }

    @Operation(summary = "货品模式导出")
    @GetMapping("/mateInventoryAdjustLog/exportMode")
    public CommonResponse<ExportInfo> exportMateInventoryAdjustLogMode(MateInventoryAdjustLogQueryModeRequest request) {
        return succeedWith(exportManager.exportMateInventoryAdjustLogMode(request));
    }

    @Operation(summary = "详情查询")
    @GetMapping("/mateInventoryAdjustLog/get/{mateInventoryAdjustLogId}")
    public CommonResponse<MateInventoryAdjustLogGetDetailResponse> getMateInventoryAdjustLogById(@PathVariable("mateInventoryAdjustLogId") Long mateInventoryAdjustLogId) {
        return succeedWith(mateInventoryAdjustLogFacade.getMateInventoryAdjustLogById(mateInventoryAdjustLogId));
    }

    @Operation(summary = "新增")
    @PostMapping("/mateInventoryAdjustLog/add")
    public CommonResponse addMateInventoryAdjustLog(@RequestBody MateInventoryAdjustLogAddRequest request) {
        request.setCreateUserCode(SPRequestContextHolder.getCurrentSystemUserLoginName());
        request.setCreateUserName(SPRequestContextHolder.getCurrentSystemUserRealName());
        mateInventoryAdjustLogFacade.addMateInventoryAdjustLog(request);
        return succeed();
    }

    @Operation(summary = "更新")
    @PutMapping("/updateMateInventoryAdjustLog/update")
    public CommonResponse updateMateInventoryAdjustLog(@RequestBody MateInventoryAdjustLogUpdateRequest request) {
        mateInventoryAdjustLogFacade.updateMateInventoryAdjustLog(request);
        return succeed();
    }

    @Operation(summary = "审核通过")
    @PutMapping("/approvedMateInventoryAdjustLog/approved/{id}")
    public CommonResponse approvedMateInventoryAdjustLog(@PathVariable("id") Long id) {
        mateInventoryAdjustLogFacade.approvedMateInventoryAdjustLog(id);
        return succeed();
    }

    @Operation(summary = "审核拒绝")
    @PutMapping("/refuseMateInventoryAdjustLog/refuse/{id}")
    public CommonResponse refuseMateInventoryAdjustLog(@PathVariable("id") Long id) {
        mateInventoryAdjustLogFacade.refuseMateInventoryAdjustLog(id);
        return succeed();
    }

    @Operation(summary = "删除")
    @PutMapping("/deleteMateInventoryAdjustLog/delete/{id}")
    public CommonResponse deleteMateInventoryAdjustLog(@PathVariable("id") Long id) {
        mateInventoryAdjustLogFacade.deleteMateInventoryAdjustLog(id);
        return succeed();
    }

}